package com.bo.service.impl;

import com.bo.mapper.DeptMapper;
import com.bo.pojo.Dept;
import com.bo.service.DeptService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

import static java.time.LocalTime.now;

/**
 * @author huangbo
 * @version 1.0.0
 */
@Service
public class DeptServiceImpl implements DeptService {
    @Autowired
    private DeptMapper deptMapper;

    @Override
    public List<Dept> list() {
        return deptMapper.list();
    }


    @Override
    public void delete(Integer id) {
        deptMapper.deleteById(id);
    }

    @Override
    public void add(Dept dept) {
        dept.setCreateTime(LocalDateTime.now());
        dept.setUpdateTime(LocalDateTime.now());
        deptMapper.insert(dept); //补充基础属性，并调用mapper接口执行新增操作
    }

    @Override
    public Dept find(Integer id) {
        return deptMapper.findById(id);
    }

    @Override
    public void update(Dept dept) {
        Dept newDept = deptMapper.findById(dept.getId());
        newDept.setName(dept.getName());    //更新姓名
        newDept.setUpdateTime(LocalDateTime.now()); //更新时间
        deptMapper.update(newDept);
    }
}
